



from datetime import datetime, timedelta

wages = {"02": 50800.8,
         "03": 19500.8,
         "04": 19500.8,
         "05": 39500.8,
         "06": 19500.8,
         "07": 19500.8}

payloads = {
"01":13266.81 + 10000,
"02":13179.16 + 35000,
"03":13062.12 + 6000,
"04":13026.67 + 5000,
"05":12993.96 + 25000,
"06":12906.25 + 10000,
"07":12873.55 + 5000}

way_pay = {
    "01-21": 2945,
    "03-20": 1000,
    "03-23": 400,
    "04-16": 1000,
    "04-21": 400,
    "05-16": 1000,
    "05-19": 400,
}



date = "08-14"

# aaaaa 查看剩余可用资金
def test_get_money():
    min_ini = 10000000
    min_date = ""
    init_money = 26973.54
    credit_card_pre = 0
    credit_card_cur = -1652.69 - 3.38 - 136.27 - 15.79 - 107
    end_date = datetime.strptime("2025-" + date, "%Y-%m-%d")
    date_list = []
    current_date = datetime.today() + timedelta(days=1)
    while current_date <= end_date:
        date_list.append(current_date.strftime("%m-%d"))
        current_date += timedelta(days=1)
    date_list.append(date)
    for date_str in date_list:
        credit_card_cur = credit_card_cur - 33
        if date_str[3:] in way_pay: # 路费
            credit_card_cur = credit_card_cur - way_pay[date_str[3:]]
        if date_str[3:] == "15": # 15号发工资
            init_money = init_money + wages[date_str[:2]]
        elif date_str[3:] == "13": # 还信用卡
            init_money = init_money + credit_card_pre
            credit_card_pre = 0
        elif date_str[3:] == "05": # 交电费网费
            init_money = init_money - 130
        elif date_str[3:] == "14": # 交房租管理费水费
            init_money = init_money - 1280 - 30 - 5
        elif date_str[3:] == "01": # 提现公积金
            init_money = init_money + 1900
        elif date_str[3:] == "20": # 还房贷
            init_money = init_money - payloads[date_str[:2]]
        elif date_str[3:] == "24": # 信用卡账单日
            credit_card_pre = credit_card_cur
            credit_card_cur = 0
        if init_money < min_ini:
            min_ini = init_money
            min_date = date_str
        if init_money < 0:
            print(date_str)
    print(init_money)





# aaaaa 税后收入计算
def test_after_tax_income():
    all_in_hand = 0
    all_tax = 0
    base_income = 19000 # 基本工资
    performance = 5000 # 绩效工资
    fund_ratio = 0.05 # 公积金比例
    pension_insurance_ratio = 0.08 # 养老保险比例
    medical_insurance_ratio = 0.02 # 医疗保险比例
    unemployment_insurance_ratio = 0.002 # 失业保险比例
    tax_credit = 8500 # 免税额度
    accumulated_taxable_amount = 0
    for i in range(1, 13):
        after_tax_income = base_income + performance - base_income * (fund_ratio + pension_insurance_ratio + medical_insurance_ratio + unemployment_insurance_ratio)
        if i == 2:
            after_tax_income = after_tax_income + 58000
        if i == 5:
            after_tax_income = after_tax_income + 58000
        tax = calculate_tax(accumulated_taxable_amount, after_tax_income - tax_credit)
        all_tax = all_tax + tax
        after_tax_income = after_tax_income - tax
        print(str(i) + "月：" + " 到手：" + str(round(after_tax_income, 2)) + " 税：" + str(round(tax, 2)))
        all_in_hand = all_in_hand + after_tax_income + base_income * fund_ratio * 2
        accumulated_taxable_amount = accumulated_taxable_amount + after_tax_income - tax_credit
    print("累计到手：" + str(round(all_in_hand, 2)))
    print("累计缴税：" + str(round(all_tax, 2)))

# 简化版的税率表（截至2023年）
tax_brackets = [
    (0, 36000, 0.03, 0),
    (36000, 144000, 0.10, 2520),
    (144000, 300000, 0.20, 16920),
    (300000, 420000, 0.25, 31920),
    (420000, 660000, 0.30, 52920),
    (660000, 960000, 0.35, 85920),
    (960000, None, 0.45, 181920)
]

def calculate_tax(year_to_date_gross, this_month_gross):
    total_gross = year_to_date_gross + this_month_gross
    previous_tax = compute_tax(year_to_date_gross)
    current_tax = compute_tax(total_gross)
    this_month_tax = current_tax - previous_tax
    return this_month_tax

def compute_tax(gross_income):
    if gross_income <= 36000:
        return gross_income * 0.03
    elif gross_income <= 144000:
        return gross_income * 0.10 - 2520
    elif gross_income <= 300000:
        return gross_income * 0.20 - 16920
    elif gross_income <= 420000:
        return gross_income * 0.25 - 31920
    elif gross_income <= 660000:
        return gross_income * 0.30 - 52920
    elif gross_income <= 960000:
        return gross_income * 0.35 - 85920
    else:
        return gross_income * 0.45 - 181920

# 使用示例
# year_to_date_principal = float(input("请输入今年截止上月累计纳税本金: "))
# this_month_principal = float(input("请输入本月纳税本金: "))
#
# this_month_tax = calculate_tax(year_to_date_principal, this_month_principal)
# print(f"本月应纳税额为: {this_month_tax:.2f}")


